//
//  SaveListTableViewCell.m
//  GoodWayClient
//
//  Created by HuiDong on 15/12/25.
//  Copyright © 2015年 HuiDong. All rights reserved.
//

#import "SaveListTableViewCell.h"

@interface SaveListTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *descrip;
@property (weak, nonatomic) IBOutlet UILabel *amount;
@property (weak, nonatomic) IBOutlet UILabel *speak;
@property (weak, nonatomic) IBOutlet UILabel *money;

- (IBAction)selectClick:(id)sender;

@end

@implementation SaveListTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype) SaveListWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"cell";
    SaveListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"SaveListTableViewCell" owner:nil options:nil] lastObject];
    }
    return cell;
}

- (void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    self.image.image = [UIImage imageNamed:dic[@"image"]];
    self.descrip.text = dic[@"descrip"];
    self.money.text = dic[@"money"];
    self.amount.text = dic[@"amount"];
    self.speak.text = dic[@"speak"];
    [self.selectBtn setBackgroundImage:[UIImage imageNamed:@"goodNotSelected.png"] forState:UIControlStateNormal];
    self.selectBtn.hidden = YES;
}

- (IBAction)selectClick:(id)sender {
    if (self.b == 0) {
        [self.selectBtn setBackgroundImage:[UIImage imageNamed:@"goodSelected.png"] forState:UIControlStateNormal];
        [self.delegate addThing:self.a];
        self.b = 1;
    }else
    {
        [self.selectBtn setBackgroundImage:[UIImage imageNamed:@"goodNotSelected.png"] forState:UIControlStateNormal];
        [self.delegate deleteThing:self.a];
        self.b = 0;
    }
}
@end
